import java.util.Stack;

/**
 * @program: LeetCode
 * @ClassName Num030_MinStack
 * @description: LeetCode : 剑指 Offer 30. 包含min函数的栈
 * @author: WXY
 * @create: 2022-12-09 13:42
 * @Version 1.0
 **/

class Num030_MinStack {
    Stack<Integer> data;
    Stack<Integer> min;
    public void MinStack() {
        data = new Stack<>();
        min = new Stack<>();
    }

    public void push(int x) {
        data.push(x);
        if (min.isEmpty()) {
            min.push(x);
        } else {
            int temp = min.peek() > x ? x : min.peek();
            min.push(temp);
        }
    }

    public void pop() {
        data.pop();
        min.pop();
    }

    public int top() {
        return data.peek();
    }

    public int min() {
        return min.peek();
    }
}
